import Vue from 'vue'
import api from './constant/api'
import store from './store/store'
import router from './router'
import App from './App.vue'
import filter from './filter'
import VueSweetAlert from 'vue-sweetalert'
import * as uiv from 'uiv'
import editor from 'vue-html5-editor'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)
Vue.use(VueSweetAlert)
Vue.use(uiv)


let options = {language: "zh-cn",visibleModules: [
    "text",
    "color",
    "font",
    "align",
    "list",
    "link",
    "unlink",
    "tabulation",
    "image",
    "hr",
    "eraser",
    "undo",
],
    image: {
        // 文件最大体积，单位字节  max file size
        sizeLimit: 512 * 1024,
        // 上传参数,默认把图片转为base64而不上传
        // upload config,default null and convert image to base64
        upload: {
            url: 'http://192.168.0.18:8090/pms' + '/api/attachment/uploadpicforhtml',
            headers: {},
            params: {},
            fieldName: 'file'
        },
        // 压缩参数,默认使用localResizeIMG进行压缩,设置为null禁止压缩
        // compression config,default resize image by localResizeIMG (https://github.com/think2011/localResizeIMG)
        // set null to disable compression
        compress: null,
        // 响应数据处理,最终返回图片链接
        // handle response data，return image url
        uploadHandler(responseText){
            //default accept json data like  {ok:false,msg:"unexpected"} or {ok:true,data:"image url"}
            var json = JSON.parse(responseText)
            console.log(json);
            if (json.code != '1') {
                this.$swal({title: "上传图片失败！", timer: 2000, type: 'error', showConfirmButton: false});
            } else {
                return 'http://192.168.0.18:8090/pms/att'+ json.data.fileName;
            }
        },
    },
};

Vue.use(editor,options)

// 将api挂载到prototype上，在组件中可以直接使用this.api访问
Vue.prototype.api = api;



let getImage = path => require('./assets/image/' + path);//获取图片路径ES6写法
Vue.prototype.getImage = getImage;//绑定到原型链中,固定路径加载静态图片

for(let p in filter){//遍历对象属性，加载所有方法到filter
    Vue.filter( p ,filter[p]);
}

let vm = new Vue({
    el: '#app',
    router,
    store,
    render: h => h(App)
}).$mount('#app');
export default vm//导出这个实